// run: $exec < input
#include <iostream>
#include <iomanip>

int const maxn = 2000;
int f[maxn][maxn];
int g[maxn][maxn];
int a[maxn];
int sum[maxn];
int n, m, l;

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin >> n >> m >> l;
	for (int i = 1; i <= n; i++) std::cin >> a[i];
	for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] ^ a[i];
	f[0][0] = 1 << 30;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= std::min(m, i); j++) {
			for (int t = 1; t <= std::min(i, l); t++) {
				int tmp = std::min(f[i - t][j - 1], sum[i] ^ sum[i - t]);
				if (tmp > f[i][j]) {
					f[i][j] = tmp;
					g[i][j] = i - t;
				}
			}
		}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= std::min(m, i); j++)
			std::cout << std::setw(5) << g[i][j] << ' ';
		std::cout << '\n';
	}
	std::cout << f[n][m] << '\n';
}

